//
//  StwxDetailViewController.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/10/23.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "StwxDetailViewController.h"

#import "STSpaceViewController.h"
#import "EPWebV2ViewController.h"

#import "StwxCommentCell.h"
#import "StwxDetailCell.h"

@interface StwxDetailViewController ()

/// 模型视图
@property (nonatomic, readonly, strong) StwxDetailViewModel* viewModel;

// UI
@property (nonatomic, weak) IBOutlet UITableView* currentTableView;
@property (nonatomic, weak) IBOutlet UIButton* zanBtn;
@property (nonatomic, weak) IBOutlet UIButton* commentBtn;
@property (nonatomic, weak) IBOutlet UIView* ctrlView;
@property (nonatomic, weak) IBOutlet UIImageView* adImgView;
@property (nonatomic, weak) IBOutlet UIButton* adImgBtn;

@property (nonatomic, strong) UIButton* shareBtn;
@property (nonatomic, strong) UIButton* collectBtn;
@property (nonatomic, strong) UIButton* downloadBtn;
@property (nonatomic, strong) MBProgressHUD* _downloadHUBView;

@property (nonatomic, assign) NSInteger _extraRowNum;

@end

@implementation StwxDetailViewController

@dynamic viewModel;

- (instancetype)initWithViewModel:(SUViewModel2 *)viewModel
{
    self = [super initWithViewModel:viewModel];
    if (self)
    {
        [self initData];
        [self initUI];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    // hide sys navBar
    self.fd_prefersNavigationBarHidden = NO;
    // 去掉侧滑pop手势
    self.fd_interactivePopDisabled = YES;
    // create subViews
    [self _setupSubViews];
    // deal action
    [self _dealAction];
    /// tableView auto rowHeight
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 100.0f;
    /// tableView rigister  cell
    [self.tableView mh_registerNibCell:[StwxDetailCell class]];
    [self.tableView mh_registerNibCell:[StwxCommentCell class]];
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
    //重置 更新 frame
}

- (void)initData
{
    self._extraRowNum = 0;
}

- (void)initUI
{
    @weakify(self);
}

- (void)_setupSubViews
{
    
}

- (UITableView*)customTableView
{
    return self.currentTableView;
}

#pragma mark - 事件处理
/// 事件处理
- (void)_dealAction
{
    @weakify(self);
    
}

#pragma mark - Override
- (void)bindViewModel
{
    [super bindViewModel];
    
    [self _setupViews];
    
    @weakify(self);
    RACSignal* willAppearSignal = [self rac_signalForSelector:@selector(viewWillAppear:)];
    [[[willAppearSignal replay] take:1] subscribeNext:^(id x)
    {
        @strongify(self);
        
        [MBProgressHUD mh_showProgressHUD:@""];
        
        [self.viewModel.requestDataCmd execute:nil];
    }];
    
    /// 1. 监听banners的数据变化
    //    [RACObserve(self.viewModel, banners) subscribeNext:^(id x) {
    //        /// 配置数据
    //        @strongify(self);
    //        self.headerView.imageURLStringsGroup = self.viewModel.banners;
    //        self.headerView.hidden = !(self.viewModel.banners.count>0);
    //    }];
    
    /// 2. 处理cell上的点击事件（PS：如果cell的数据不是异步请求的数据，那么就用 RACSubject 代替代理（block） ，否则也可以用 RACCommand代替代理（block），但是建议用 RACSubject，但是RACSubject过于灵活）
    /// cell被点击
    self.viewModel.didSelectCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(NSIndexPath *indexPath) {
        @strongify(self);
        // 跳转到活动详情
        //        [self _pushToPublicViewControllerWithTitle:@"活动详情" indexPath:indexPath];
        
//        [self _push2ExpertInfoVCByIndexPath:indexPath];
        
        return [RACSignal empty];
    }];
    
    [[self.viewModel.requestDataCmd.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
    {
        @strongify(self);
        
        if (x!=nil)
            [self.viewModel.requestRemoteDataCommand execute:@0];
    }];
    [[self.viewModel.requestDataCmd.errors deliverOnMainThread] subscribeNext:^(NSError* error)
    {
        @strongify(self);
        
        [MBProgressHUD mh_hideHUD];
        
        /// 处理验证错误的error
        if ([error.domain isEqualToString:SUCommandErrorDomain]) {
            [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
            return ;
        }
        [MBProgressHUD mh_showErrorTips:error];
    }];
    
    [[self.viewModel.requestRemoteDataCommand.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
     {
         @strongify(self);
         
         [MBProgressHUD mh_hideHUD];
         
         if (self._extraRowNum == 0)
         {
             self._extraRowNum = 1;
             [self.tableView reloadData];
             
             if (!self.viewModel.isHaveDetailCtrl)
             {
                 [self tableViewDidFinishTriggerHeader:NO reload:NO];
             }
         }
     }];
    [[self.viewModel.requestRemoteDataCommand.errors deliverOnMainThread] subscribeNext:^(NSError* error)
     {
         @strongify(self);
         
         [MBProgressHUD mh_hideHUD];
         
         /// 处理验证错误的error
         if ([error.domain isEqualToString:SUCommandErrorDomain]) {
             [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
             return ;
         }
         [MBProgressHUD mh_showErrorTips:error];
     }];
    
    RACSignal* zanBtnSignal = [self.zanBtn rac_signalForControlEvents:UIControlEventTouchUpInside];
    [zanBtnSignal subscribeNext:^(id x) {
        
        @strongify(self);
        
        [MBProgressHUD mh_showProgressHUD:@""];
        
        [self _btnListener_zan];
    }];
    
    RACSignal* commentBtnSignal = [self.commentBtn rac_signalForControlEvents:UIControlEventTouchUpInside];
    [commentBtnSignal subscribeNext:^(id x) {
        
        @strongify(self);
        
        [MBProgressHUD mh_showProgressHUD:@""];
        
        [self _btnListener_comment];
    }];
    
    [self.viewModel.requestCollectCmd.executionSignals.switchToLatest subscribeNext:^(id x)
    {
        @strongify(self);
        
        [MBProgressHUD mh_hideHUD];
        
        [MBProgressHUD mh_showTips:x];
    }];
    
    [self.viewModel.requestCollectCmd.errors subscribeNext:^(NSError* error)
    {
        @strongify(self);
        
        [MBProgressHUD mh_hideHUD];
        
        /// 处理验证错误的error
        if ([error.domain isEqualToString:SUCommandErrorDomain]) {
            [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
            return ;
        }
        [MBProgressHUD mh_showErrorTips:error];
    }];
    
    [self.viewModel.requestGoodCmd.executionSignals.switchToLatest subscribeNext:^(id x)
     {
         @strongify(self);
         
         [MBProgressHUD mh_hideHUD];
         
         [MBProgressHUD mh_showTips:x];
     }];
    
    [self.viewModel.requestGoodCmd.errors subscribeNext:^(NSError* error)
     {
         @strongify(self);
         
         [MBProgressHUD mh_hideHUD];
         
         /// 处理验证错误的error
         if ([error.domain isEqualToString:SUCommandErrorDomain]) {
             [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
             return ;
         }
         [MBProgressHUD mh_showErrorTips:error];
     }];
    
    [[[self.viewModel.checkDownloadCmd.executing deliverOnMainThread] skip:1] subscribeNext:^(id x)
     {
         @strongify(self)
         
         //这里的x是一个带有数据的信号,若这个信号存在那么就说明command还在执行,否则说明没有执行或者执行完毕
         if ([x boolValue])
         {
             NSLog(@"正在执行");
             
             self._downloadHUBView = [MBProgressHUD mh_showProgressHUD:@""];
         }
         else
         {
             NSLog(@"执行未开始/执行完毕");
         }
     }];
    
    [[self.viewModel.checkDownloadCmd.errors deliverOnMainThread] subscribeNext:^(NSError* error)
     {
         @strongify(self)
         
         if ([error.domain isEqualToString:SUCommandErrorDomain])
         {
             [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
             return;
         }
         [MBProgressHUD mh_showErrorTips:error];
     }];
    
    [[[self.viewModel.downloadCmd.executing deliverOnMainThread] skip:1] subscribeNext:^(id x)
     {
         @strongify(self)
         
         //这里的x是一个带有数据的信号,若这个信号存在那么就说明command还在执行,否则说明没有执行或者执行完毕
         if ([x boolValue])
         {
             NSLog(@"正在执行");
             
             self._downloadHUBView = [MBProgressHUD mh_showProgressHUD:@"下载中。。。"];
         }
         else
         {
             NSLog(@"执行未开始/执行完毕");
         }
     }];
    
    [self.viewModel.downloadCmd.executionSignals subscribeNext:^(RACSignal* signal)
     {
         @strongify(self)
         
         @weakify(self)
         [[signal deliverOnMainThread] subscribeNext:^(id x)
          {
              @strongify(self)
              
              if ([x isKindOfClass:[NSNumber class]])
              {
                  NSString* strTip = HCStrFormat(@"下载中。。。%d%%", (int)([x floatValue]*100));
                  
                  if (self._downloadHUBView)
                  {
                      self._downloadHUBView.detailsLabel.text = strTip;
                  }
              }
          } completed:^
          {
              [MBProgressHUD mh_hideHUD];
              [MBProgressHUD mh_showTips:@"文件已经保存在默认下载目录中"];
              
              ArticleInfoData* articleInfoData = self.viewModel.detailItemVM.data;
              
              DataManager* dataMgr = [DataManager sharedDataManager];
              [dataMgr saveOfflineFileHistory:[articleInfoData dbData]];
          }];
     }];
    
    [[self.viewModel.fileCmd.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
    {
        @strongify(self);
        
        [self _push2FileVC:x];
    }];
    
    [[[RACObserve(self.viewModel, detailItemVM) distinctUntilChanged] filter:^BOOL(id value) {
        
        return value != nil;
    }] subscribeNext:^(id x)
    {
        @strongify(self);
        
        [self _setupDetailItem];
    }];
}

- (void)_setupDetailItem
{
    @weakify(self);
    
    [[self.viewModel.detailItemVM.goUserSpaceCommand.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
     {
         @strongify(self);
         
         [self _push2UserSpaceVC];
     }];
}

- (void)_setupViews
{
    @weakify(self);
    [RACObserve(self.viewModel, isHaveDetailCtrl) subscribeNext:^(id x)
    {
        @strongify(self);
        
        BOOL isHaveDetailCtrl = [x boolValue];
        
        for (NSLayoutConstraint* curConstraint in self.ctrlView.constraints)
        {
            if (curConstraint.firstAttribute == NSLayoutAttributeHeight)
            {
                curConstraint.constant = isHaveDetailCtrl ? 44.0f : 0.0f;
                
                break;
            }
        }
    }];
    
    [RACObserve(self.viewModel, isHaveDownload) subscribeNext:^(id x)
     {
         @strongify(self);
         
         @weakify(self);
         
         BOOL isHaveDownload = [x boolValue];
         
         CGFloat navSubViewOffset = 12.0f;
         
         NSInteger viewNum = isHaveDownload ? 3 : 2;
         
         UIView* rightItemView = [[UIView alloc] initWithFrame:(CGRect) {0, 0, navSubViewOffset*(viewNum - 1) + 32*viewNum, 44}];
         
         UIView* shareNavView = [[UIView alloc] initWithFrame:(CGRect) {0, 0, 32.0f, 44.0f}];
         shareNavView.tag = 10;
         {
             UIImageView* iconImgView = [[UIImageView alloc] initWithFrame:(CGRect) {0, 0, 32, 26}];
             iconImgView.image = MHImageNamed(@"icon_fenxiang");
             iconImgView.contentMode = UIViewContentModeCenter;
             [shareNavView addSubview:iconImgView];
             
             UILabel* label = [[UILabel alloc] initWithFrame:(CGRect) {0, CGRectGetMaxY(iconImgView.frame), 32, 18}];
             label.font = [UIFont systemFontOfSize:10.0f];
             label.text = @"分享";
             label.textAlignment = NSTextAlignmentCenter;
             [shareNavView addSubview:label];
             
             UIButton* tickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
             tickBtn.frame = (CGRect) {0, 0, 32, 44};
             tickBtn.tag = 10;
             [shareNavView addSubview:tickBtn];
             self.shareBtn = tickBtn;
             
             RACSignal* shareBtnSignal = [tickBtn rac_signalForControlEvents:UIControlEventTouchUpInside];
             [shareBtnSignal subscribeNext:^(id x) {
                 
                 @strongify(self);
                 
                 [self _btnListener_share];
             }];
         }
         [rightItemView addSubview:shareNavView];
         
         UIView* collectNavView = [[UIView alloc] initWithFrame:(CGRect) {12 + 32, 0, 32.0f, 44.0f}];
         collectNavView.tag = 11;
         {
             UIImageView* iconImgView = [[UIImageView alloc] initWithFrame:(CGRect) {0, 0, 32, 26}];
             iconImgView.image = MHImageNamed(@"icon_sc");
             iconImgView.contentMode = UIViewContentModeCenter;
             iconImgView.tag = 100;
             iconImgView.hidden = self.viewModel.isCollect;
             [collectNavView addSubview:iconImgView];
             UIImageView* iconOnImgView = [[UIImageView alloc] initWithFrame:(CGRect) {0, 0, 32, 26}];
             iconOnImgView.image = MHImageNamed(@"zan_hx");
             iconOnImgView.contentMode = UIViewContentModeCenter;
             iconOnImgView.hidden = !self.viewModel.isCollect;
             iconOnImgView.tag = 101;
             [collectNavView addSubview:iconOnImgView];
             
             UILabel* label = [[UILabel alloc] initWithFrame:(CGRect) {0, CGRectGetMaxY(iconImgView.frame), 32, 18}];
             label.font = [UIFont systemFontOfSize:10.0f];
             label.text = @"收藏";
             label.textAlignment = NSTextAlignmentCenter;
             [collectNavView addSubview:label];
             
             UIButton* tickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
             tickBtn.frame = (CGRect) {0, 0, 32, 44};
             tickBtn.tag = 10;
             [collectNavView addSubview:tickBtn];
             self.collectBtn = tickBtn;
             
             RACSignal* collectBtnSignal = [tickBtn rac_signalForControlEvents:UIControlEventTouchUpInside];
             [collectBtnSignal subscribeNext:^(id x) {
                 
                 @strongify(self);
                 
                 [MBProgressHUD mh_showProgressHUD:@""];
                 
                 [self _btnListener_collect];
             }];
         }
         [rightItemView addSubview:collectNavView];
         
         if (isHaveDownload)
         {
             UIView* downloadNavView = [[UIView alloc] initWithFrame:(CGRect) {12*2 + 32*2, 0, 32.0f, 44.0f}];
             downloadNavView.tag = 12;
             {
                 downloadNavView.layer.masksToBounds = YES;
                 
                 UIImageView* iconImgView = [[UIImageView alloc] initWithFrame:(CGRect) {0, 0, 32, 26}];
                 iconImgView.image = MHImageNamed(@"icon_xiazai");
                 iconImgView.contentMode = UIViewContentModeCenter;
                 [downloadNavView addSubview:iconImgView];
                 
                 UILabel* label = [[UILabel alloc] initWithFrame:(CGRect) {0, CGRectGetMaxY(iconImgView.frame), 32, 18}];
                 label.font = [UIFont systemFontOfSize:10.0f];
                 label.text = @"下载";
                 label.textAlignment = NSTextAlignmentCenter;
                 [downloadNavView addSubview:label];
                 
                 UIButton* tickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                 tickBtn.frame = (CGRect) {0, 0, 32, 44};
                 tickBtn.tag = 10;
                 [downloadNavView addSubview:tickBtn];
                 self.downloadBtn = tickBtn;
                 
                 RACSignal* downloadBtnSignal = [tickBtn rac_signalForControlEvents:UIControlEventTouchUpInside];
                 [downloadBtnSignal subscribeNext:^(id x) {
                     
                     @strongify(self);
                     
                     [MBProgressHUD mh_showProgressHUD:@""];
                     
                     [self _btnListener_download];
                 }];
             }
             [rightItemView addSubview:downloadNavView];
         }
         
         //        [shareNavView mas_makeConstraints:^(MASConstraintMaker *make)
         //         {
         //             make.left.mas_equalTo(0);
         //             make.right.mas_equalTo(collectNavView.mas_left).mas_offset(12);
         //             make.top.mas_equalTo(0);
         //             make.bottom.mas_equalTo(0);
         //         }];
         //        [collectNavView mas_makeConstraints:^(MASConstraintMaker *make)
         //         {
         //             make.left.mas_equalTo(shareNavView.mas_right).mas_offset(12);
         //             make.right.mas_equalTo(downloadNavView.mas_left).mas_offset(12);
         //             make.top.mas_equalTo(0);
         //             make.bottom.mas_equalTo(0);
         //         }];
         //        [downloadNavView mas_makeConstraints:^(MASConstraintMaker *make)
         //         {
         //             make.left.mas_equalTo(collectNavView.mas_right).mas_offset(12);
         //             make.right.mas_equalTo(0);
         //             make.top.mas_equalTo(0);
         //             make.bottom.mas_equalTo(0);
         //         }];
         
         UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightItemView];
         self.navigationItem.rightBarButtonItem = rightItem;
     }];
    [RACObserve(self.viewModel, isCollect) subscribeNext:^(id x)
     {
         @strongify(self);
         
         UIView* customView = self.navigationItem.rightBarButtonItem.customView;
         if (customView)
         {
             BOOL isFinded = NO;
             for (UIView* subView in customView.subviews)
             {
                 if (subView.tag == 11)
                 {
                     isFinded = YES;
                     
                     break;
                 }
             }
             
             if (isFinded)
             {
                 UIView* collectNavView = [customView viewWithTag:11];
                 UIImageView* uncollectImgView = [collectNavView viewWithTag:100];
                 UIImageView* collectImgView = [collectNavView viewWithTag:101];
                 
                 BOOL isCollect = [x boolValue];
                 uncollectImgView.hidden = isCollect;
                 collectImgView.hidden = !isCollect;
             }
         }
     }];
    [RACObserve(self.viewModel, isPraise) subscribeNext:^(id x)
     {
         @strongify(self);
         
         BOOL isPraise = [x boolValue];
         
         self.zanBtn.selected = isPraise;
     }];
}

/// config  cell
- (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
{
    NSString* cellIdentifier = indexPath.row == 0 ? NSStringFromClass([StwxDetailCell class]) : NSStringFromClass([StwxCommentCell class]);
    
    return [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}

/// config  data
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(NSObject *)object
{
    /// config data (PS：由于MVVM主要是View与数据之间的绑定，但是跟 setViewModel: 差不多啦)
    
    if (indexPath.row>0)
    {
        StwxCommentItemViewModel* curObj = (StwxCommentItemViewModel*)object;
        StwxCommentCell* curCell = (StwxCommentCell*)cell;
        [curCell bindViewModel:curObj];
    }
    else
    {
        StwxDetailItemViewModel* curObj = (StwxDetailItemViewModel*)object;
        StwxDetailCell* curCell = (StwxDetailCell*)cell;
        [curCell bindViewModel:curObj];
    }
}

/// 文本内容区域
- (UIEdgeInsets)contentInset
{
    return UIEdgeInsetsZero;
}

#pragma mark - UITableViewDelegate
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    /// 由于使用系统的autoLayout来计算cell的高度，每次滚动时都要重新计算cell的布局以此来获得cell的高度 这样一来性能不好
//    /// 所以笔者采用实现计算好的cell的高度
//
//    return [self.viewModel.dataSource[indexPath.row] cellHeight];
//}

////////////////// 以下为UI代码，不必过多关注 ///////////////////
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return .0001f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    /// FIXED : when data is empty ，the backgroundColor is exist
    return .0001f;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.viewModel.dataSource.count + self._extraRowNum;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self tableView:tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    
    // fetch object
    id object = nil;
    
    if (indexPath.row != 0)
    {
        if (!self.viewModel.shouldMultiSections) object = self.viewModel.dataSource[indexPath.row - self._extraRowNum];
    }
    else
    {
        object = self.viewModel.detailItemVM;
    }
    
    /// bind model
    [self configureCell:cell atIndexPath:indexPath withObject:(id)object];
    
    return cell;
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
}

#pragma mark - Listener
- (void)_btnListener_share
{
    NSLog(@"Stwx Detail Share Btn Click!");
}

- (void)_btnListener_collect
{
    NSLog(@"Stwx Detail Collect Btn Click!");
    
    [self.viewModel.requestCollectCmd execute:nil];
}

- (void)_btnListener_download
{
    NSLog(@"Stwx Detail Download Btn Click!");
    
    if (self.viewModel.downloadNeedCoin > 0)
    {
        //弹出选择框
        NSString* strMsg = HCStrFormat(@"下载将消耗生态币数量:%d", (int)self.viewModel.downloadNeedCoin);
        [UIAlertView bk_showAlertViewWithTitle:@"下载提示" message:strMsg cancelButtonTitle:@"取消" otherButtonTitles:@[@"下载"] handler:^(UIAlertView *alertView, NSInteger buttonIndex)
         {
             if (buttonIndex == 1)
             {
                 [self.viewModel.checkDownloadCmd execute:nil];
             }
         }];
    }
    else
    {
        [self.viewModel.downloadCmd execute:nil];
    }
}

- (void)_btnListener_zan
{
    NSLog(@"Stwx Detail Zan Btn Click!");
    
    [self.viewModel.requestGoodCmd execute:nil];
}

- (void)_btnListener_comment
{
    NSLog(@"Stwx Detail Comment Btn Click!");
}

#pragma mark - 跳转
//- (void)_push2ExpertInfoVCByIndexPath:(NSIndexPath*)indexPath
//{
//    ExpertItemViewModel* itemVM = self.viewModel.dataSource[indexPath.row];
//
//    ExpertInfoViewModel* vm = [[ExpertInfoViewModel alloc] initWithParams:@{SUViewModelTitleKey:itemVM.data.userName}];
//    vm.expertData = itemVM.data;
//    ExpertInfoViewController* vc = [[ExpertInfoViewController alloc] initWithViewModel:vm];
//    [self.navigationController pushViewController:vc animated:YES];
//}

- (void)_push2UserSpaceVC
{
    ArticleInfoData* aInfoData = self.viewModel.detailItemVM.data;
    
    STSpaceViewModel* vm = [[STSpaceViewModel alloc] initWithParams:@{}];
    vm.userID = aInfoData.userID;
    STSpaceViewController* vc = [[STSpaceViewController alloc] initWithViewModel:vm];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)_push2FileVC:(id)x
{
    ArticleInfoData* data = x;
    
    NSString* name = [data.download componentsSeparatedByString:@"/"].lastObject;
    NSString* file = data.download;
    
    EPWebV2ViewModel* vm = [[EPWebV2ViewModel alloc] initWithParams:@{}];
    vm.webName = name;
    vm.webUrl = file;
    EPWebV2ViewController* vc = [[EPWebV2ViewController alloc] initWithViewModel:vm];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    MHDealloc;
}

@end
